/**
 * Date Modified: $Date: 2009-08-28 10:39:55 +1000 (Fri, 28 Aug 2009) $
 * Version: $Revision: 129 $
 * 
 * Copyright 2008 The Australian National University (ANU)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
//package org.ands.rifcs.example;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.*;

import javax.xml.parsers.ParserConfigurationException;


import org.ands.rifcs.base.*;

import org.xml.sax.SAXException;

public class Dataset
{
	private static RIFCS rifcs = null;

    public static void main(String[] args) throws RIFCSException, FileNotFoundException, SAXException, ParserConfigurationException, IOException
    {
        RIFCSWrapper mw = new RIFCSWrapper();
        rifcs = mw.getRIFCSObject();

        String[][] datasets = {
        	/* key
        	 * uri
        	 * namePart
        	 * url
        	 * hospital relation
        	 * disease group relation
        	 * person relation
        	 * subject
        	 * description 
        	 */
        //MRI Images, RMH
        	{"http://bit.ly/e2viVx",
        	 "http://bit.ly/e2viVx",
        	 "MRI Images, RMH",
        	 "http://bit.ly/e2viVx",
        	 "http://www.mh.org.au/www/342/1001127/displayarticle/1001205.html", //royal melb. hospital
        	 "http://bit.ly/dWzloh", //MRI Images
        	 "patricia_desmond_29715",  //Patricia Desmond
        	 "Medical Imaging, MRI Images",
        	 "MRI Images database at the Royal melbourne Hospital"
        	},
        	
        	
        //PETImg PMCI
        	{"http://bit.ly/fhoWZt",
        	 "http://bit.ly/fhoWZt",
        	 "PETImg, PMCI",
        	 "http://bit.ly/fhoWZt",
        	 "http://www.petermac.org/Research/ResearchHome", //Peter MacCallum Cancer Centre
        	 "http://bit.ly/dVEFOs", //PET Scan
        	 "david_binn_19958", //David Binn
        	 "Medical Imaging, PET Scans",
        	 "PET scans, Radiology, at Peter MacCallum Cancer Centre Melbourne"
        	},
        	
        	
        //BRAF LICR
        	{"http://bit.ly/fLFR3N",
        	 "http://bit.ly/fLFR3N",
        	 "BRAF LICR",
        	 "http://bit.ly/fLFR3N",
        	 "http://www.alfredhealth.org.au/Page.aspx?ID=23, http://www.ludwig.edu.au/", //Alfred and Ludwig Institute 
        	 "http://bit.ly/fTVfyS", //Colorectal Cancer (Lab Results)
        	 "jayesh_desai_583", //Jayesh Desai
        	 "Lab Results, Colorectal Cancer",
        	 "Results of a study by the Ludwig Institute for Cancer Research on the BRAF tumour marker in Colorectal Cancer samples"
        	},
        	
        //Biomarkers RMH
        	{"http://bit.ly/gq2CBK",
        	 "http://bit.ly/gq2CBK",
        	 "Biomarkers RMH",
        	 "http://bit.ly/gq2CBK",
        	 "http://www.mh.org.au/www/342/1001127/displayarticle/1001205.html", //Royal Melbourne Hospital 
        	 "http://bit.ly/g1ySEV", //Breast cancer (lab results)
        	 "peter_gibbs_1161", //Peter Gibbs
        	 "Lab Results, Breast Cancer",
        	 "Results of Biomarker testing on tissue and blood. Includes demographics, sample testing institution, staging and date of sample collection and testing. Tests include CEA, MSI, EGFR etc."
        	},
        	 	
        //Accord v1 Breast RMH/WH
        	{"http://bit.ly/g8dLOx",
        	 "http://bit.ly/g8dLOx",
        	 "Accord v1 Breast RMH/WH",
        	 "http://bit.ly/g8dLOx",
        	 "http://www.mh.org.au/www/342/1001127/displayarticle/1001205.html, http://www.wh.org.au/Research/index.aspx", //royal melb. hospital, western hospital 
        	 "http://bit.ly/dH2YKK", //breast cancer
        	 "peter_gibbs_1161", //Peter Gibbs
        	 "Oncology, Breast Cancer",
        	 "Clinical data on breast cancer patients including sex, date of birth, date of diagnosis, pathology and staging."
        	},

        	 
        //Breast Cancer BH
        	{"http://bit.ly/eVPP7c",
        	 "http://bit.ly/eVPP7c",
        	 "Breast Cancer BH",
        	 "http://bit.ly/eVPP7c",
        	 "http://www.easternhealth.org.au/locations/boxhill/opening.aspx", //Box Hill hospital
        	 "http://bit.ly/dH2YKK", //breast cancer
        	 "jacquie_chirgwin_1130", //Jacquie Chirgwin
        	 "Oncology, Breast Cancer",
        	 "Clinical data on breast cancer patients including demographics, symptoms, history, staging, treatments, clinical trials, etc"
        	},
        	
        	
        //Breast Cancer SVHM
        	{"http://bit.ly/g3cUDf",
        	 "http://bit.ly/g3cUDf",
        	 "Breast Cancer SVHM",
        	 "http://bit.ly/g3cUDf",
        	 "http://www.svhm.org.au/research/Pages/research.aspx", //St vincent's hospital melbourne
        	 "http://bit.ly/dH2YKK", //Breast Cancer
        	 "michael_henderson_5161", //Michael Henderson
        	 "Oncology, Breast Cancer",
        	 "Clinical data on breast cancer patients including sex, date of birth, date of diagnosis, surgery, pathology, staging, therapy, follow up, etc."
        	},
        	
        	
        //Accord v2 Sarcoma PMCI
        	{"http://bit.ly/fRdPSt",
        	 "http://bit.ly/fRdPSt",
        	 "Accord v2 Sarcoma PMCI",
        	 "http://bit.ly/fRdPSt",
        	 "http://www.petermac.org/Research/ResearchHome", //Peter MacCallum Cancer Centre
        	 "http://bit.ly/i8JhxX", //Sarcoma
        	 "jayesh_desai_583", //Jayesh Desai
        	 "Oncology, Sarcoma",
        	 "Clinical data on sarcoma patients including sex, date of birth, date of diagnosis, pathology, staging, therapy, follow up, etc."
        	},
        	
        	
        	
        //Pituitary Tumours RAH
        	{"http://bit.ly/eEV9pz",
        	 "http://bit.ly/eEV9pz",
        	 "Pituitary Tumours RAH",
        	 "http://bit.ly/eEV9pz",
        	 "http://www.rah.sa.gov.au/homepage.php#", //royal adelaide hospital
        	 "http://bit.ly/fzqu81", //pituitary cancer
        	 "david_torpy_612", //David Torpy
        	 "Oncology, Pituitary Cancer",
        	 "Ongoing database for the study of pituitary tumours and acromegaly patients, including incidence, symptoms and treatment"
        	},
        	
        //Pituitary Tumours RMH
        	{"http://bit.ly/fhprfO",
        	 "http://bit.ly/fhprfO",
        	 "Pituitary Tumours RMH",
        	 "http://bit.ly/fhprfO",
        	 "http://www.mh.org.au/www/342/1001127/displayarticle/1001205.html", //Royal Melbourne Hospital 
        	 "http://bit.ly/fzqu81", //pituitary cancer
        	 "niki_maartens_423", //Niki Maartens
        	 "Oncology, Pituitary Cancer",
        	 "Ongoing database for the study of pituitary tumours and acromegaly patients, including incidence, symptoms and treatment"
        	}
        	
        };
        
        
        for(int i=0;i<datasets.length;i++){
        	
        
        	RegistryObject r = rifcs.newRegistryObject();
        	
        	r.setKey(datasets[i][0]);
        	r.setGroup("BioGrid");
        	r.setOriginatingSource("https://services.ands.org.au/sandbox/orca");
        
        	Collection myCollec = r.newCollection();
        	myCollec.setType("repository");
        	myCollec.setDateAccessioned("2011-03-21T04:38:00Z");
        	myCollec.setDateModified("2011-03-21T04:38:00Z");
        
        	Identifier ident = myCollec.newIdentifier();
        	ident.setType("uri");
        	ident.setValue(datasets[i][1]);
        	myCollec.addIdentifier(ident);
        	Name n1 = myCollec.newName(); 
        	n1.addNamePart(datasets[i][2],"title");
        	myCollec.addName(n1);
        	Location loc = myCollec.newLocation();
        	Address add = loc.newAddress();
        	Electronic elec = add.newElectronic();
        	elec.setType("url");
        	elec.setValue(datasets[i][3]);
        	add.addElectronic(elec);
        	loc.addAddress(add);
        	myCollec.addLocation(loc);
        
        	RelatedObject relObj = myCollec.newRelatedObject();
        	relObj.setKey("www.biogrid.gov.au");
        	relObj.addRelation("isLocatedIn", null, null, null);
        	myCollec.addRelatedObject(relObj);
        
        	//Hospital relation
        	String hospitals[] = datasets[i][4].split(",");
        	for(int k=0;k<hospitals.length;k++){
        		RelatedObject relObj2 = myCollec.newRelatedObject();
        		relObj2.setKey(hospitals[k]);
            	relObj2.addRelation("isOwnedBy", null, null, null);
            	myCollec.addRelatedObject(relObj2);
        	}
        	
        
        	//Disease Group relation
        	String disGroups[] = datasets[i][5].split(",");
        	for(int m=0;m<disGroups.length;m++){
        		RelatedObject relObj3 = myCollec.newRelatedObject();
            	relObj3.setKey(disGroups[m]);
            	relObj3.addRelation("isDescribedBy", null, null, null);
            	myCollec.addRelatedObject(relObj3);
        	}
        	
        
        	//Owner relation
        	String owners[] = datasets[i][6].split(",");
        	for(int m=0;m<owners.length;m++){
        		RelatedObject relObj4 = myCollec.newRelatedObject();
            	relObj4.setKey(owners[m]);
            	relObj4.addRelation("isManagedBy", null, null, null);
            	myCollec.addRelatedObject(relObj4);
        	}
        
        	myCollec.addSubject(datasets[i][7], "local",null);
        	myCollec.addDescription(datasets[i][8], "brief",null);
        	r.addCollection(myCollec);
        	rifcs.addRegistryObject(r);
        
       
        }
	    mw.validate();

	    FileOutputStream outputFile=null;
	    try{
	    	outputFile = new FileOutputStream("dataset2.xml");
	    	
	    }
	    catch(IOException e1){
	    	System.out.println("Error writing to diseaseGroup.xml");
	    }
	    
		
		mw.write(outputFile);
		System.out.println("Successfully written to XML file.");
    }
}